package com.xing.algorithm.string;

/**
 * 是否是回文字符串
 */
public class Palindrome {
    public static boolean isPalindrome(String s) {
        if(s == null || s.equals("")) {
            return true;
        }

        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < s.length(); i ++) {
            char c = s.charAt(i);
            if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ) {
                sb.append(c);
            }
            if(c >= '0' && c <= '9'){
                sb.append(c);
            }
        }

        String old = sb.toString().toLowerCase();
        String now = sb.reverse().toString().toLowerCase();

        if(old.equals(now)) {
            return true;
        }

        return false;
    }

    public static void main(String[] args) {
        System.out.println(isPalindrome("A man, a plan, a canal: Panama"));
    }
}
